/*
 * @Description: C20出行看板  OrderStatistics
 * @version: 
 * @Company: 
 * @Author: ZhengZhuang
 * @Date: 2019-08-26 16:48:39
 * @LastEditors: Please set LastEditors
 * @LastEditTime: 2019-12-06 11:25:43
 */

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:C20Driver/model/get_driver_operate_info_model.dart';
import 'package:C20Driver/service/request.dart';
import 'package:C20Driver/widget/spinkit.dart';

class OrderStatistics extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text('C20出行看板'),
        elevation: 0,
      ),
      body: Container(
        color: Color(0xffEFF3F9),
        padding: EdgeInsets.only(
          left: ScreenUtil().setWidth(30.0),
          right: ScreenUtil().setWidth(30.0),
        ),
        child: FutureBuilder(
          future: Request.getDriverOperateInfo(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.hasData) {
              var getDriverOperateInfo =
                  GetDriverOperateInfo.fromJson(snapshot.data);
              return Column(
                children: <Widget>[
                  SizedBox(
                    height: ScreenUtil().setWidth(36),
                  ),
                  _formStatisticsWidget(context, getDriverOperateInfo),
                  SizedBox(
                    height: ScreenUtil().setWidth(36),
                  ),
                  _formTransactionRate(context, getDriverOperateInfo),
                ],
              );
            } else {
              return Spinkit();
            }
          },
        ),
      ),
    );
  }

  /// 今日表单统计
  Widget _formStatisticsWidget(context, GetDriverOperateInfo data) {
    return Card(
      color: Colors.transparent,
      elevation: 0,
      child: Container(
        width: ScreenUtil().setWidth(700.0),
        height: ScreenUtil().setWidth(180.0),
        decoration: BoxDecoration(
            color: Color(0xffffffff),
            borderRadius:
                BorderRadius.all(Radius.circular(ScreenUtil().setWidth(32)))),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            _statisticsList('${data.profitToday}', '今日流水'),
            _statisticsList('${data.receiptToday}', '今日接单'),
            _statisticsList('${data.online}', '在线时长'),
          ],
        ),
      ),
    );
  }

  /// 今日成交率
  Widget _formTransactionRate(context, GetDriverOperateInfo data) {
    return Card(
      color: Colors.transparent,
      elevation: 0,
      child: Container(
        width: ScreenUtil().setWidth(700.0),
        height: ScreenUtil().setWidth(180.0),
        decoration: BoxDecoration(
            color: Color(0xffffffff),
            borderRadius:
                BorderRadius.all(Radius.circular(ScreenUtil().setWidth(32)))),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.spaceAround,
          children: <Widget>[
            _statisticsList('${data.refuse}', '拒单数'),
            _statisticsList('${data.deal}', '成交率'),
            _statisticsList('${data.complaint}', '投诉率'),
          ],
        ),
      ),
    );
  }

  // 统计数据列表
  Widget _statisticsList(title, des) {
    return Container(
      width: ScreenUtil().setWidth(155.0),
      color: Colors.white,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          _statisticsTitle(title),
          SizedBox(
            height: ScreenUtil().setWidth(20.0),
          ),
          _statisticsDes(des),
        ],
      ),
    );
  }

  // 统计数据title
  Widget _statisticsTitle(title) {
    return Text(
      title,
      maxLines: 1,
      style: TextStyle(
        fontSize: ScreenUtil().setSp(48.0),
        color: Colors.black,
        fontWeight: FontWeight.w700,
      ),
    );
  }

  // 统计数据描述
  Widget _statisticsDes(title) {
    return Text(
      title,
      style: TextStyle(
        fontSize: ScreenUtil().setSp(28.0),
        color: Color.fromARGB(255, 93, 93, 93),
        fontWeight: FontWeight.w700,
      ),
    );
  }
}
